Skip to main content

Functions

Create SQL Function

This interface allows you to create SQL functions and manage them efficiently with AI assistance. You can define the function name, parameters, return type, and use AI to generate the function code automatically.

Interface Overview

The Create Function screen consists of the following elements:

  • Name:
    • A text input field where you can enter the name of the function.
    • Example: calculateTax.

Code Editor

The center of the screen features a code editor where you can manually write or edit the function. This editor allows you to define the logic of your function in SQL or any other supported query language.

  • Code Editor Features:
    • Syntax highlighting for SQL.
    • A dark theme for better focus.
    • Example: Define the function logic here.

Params and Return Type

To the right of the editor, there are two buttons:

  • Params:

    • Use this button to add parameters for the function (e.g., input values such as numbers or strings).
  • Return Type:

    • Define the return type of the function (e.g., integer, string, etc.).

AI-Generated Function Code

The Generate Function Code with AI section allows you to generate the function code automatically based on the information provided.

  • Message Field:

    • You can add a message or description in this field to guide the AI in generating the SQL function code.
    • Example: "Generate a SQL function to calculate tax based on income."
  • Send Button:

    • Click this button to send your request to the AI, which will generate the appropriate function code.

Sample Generated SQL Function

CREATE FUNCTION calculateTax (income DECIMAL)
RETURNS DECIMAL
BEGIN
DECLARE taxRate DECIMAL(5, 2);
SET taxRate = 0.15; -- Example tax rate of 15%

RETURN income * taxRate;
END;